#include<bits/stdc++.h>
using namespace std;
map<string,set<int>>title,author,key,pub,year;
void query(map<string,set<int>>&m,string &query){
    if(m.find(query)!=m.end()){
        for(auto it=m[query].begin();it!=m[query].end();it++){
            printf("%07d\n",*it);
        }
    }
    else{
        printf("Not Found\n");
    }
}

int main(){
    //freopen("in.txt","r",stdin);

    int N;
    scanf("%d",&N);

    for(int i=0;i<N;i++){
        int id;string ttitle,tauthor,tkey,tpub,tyear;
        scanf("%d\n",&id);
        getline(cin,ttitle);
        title[ttitle].insert(id);
        getline(cin,tauthor);
        author[tauthor].insert(id);
        while(cin>>tkey){
            key[tkey].insert(id);
            char c=getchar();
            if(c=='\n'){break;}
        }
        getline(cin,tpub);
        pub[tpub].insert(id);
        getline(cin,tyear);
        year[tyear].insert(id);
    }
    int M;
    scanf("%d",&M);

    for(int i=0;i<M;i++){
        int num;string que;
        scanf("%d: ",&num);
        getline(cin,que);
        printf("%d: ",num);
        cout<<que<<endl;
        if(num==1){query(title,que);}
        else if(num==2){query(author,que);}
        else if(num==3){query(key,que);}
        else if(num==4){query(pub,que);}
        else if(num==5){query(year,que);}
    }
}
